//
//  FDShopDetailHeaderView.m
//  FD
//
//  Created by Yasin on 2018/10/13.
//  Copyright © 2018年 ZhiYuan Network. All rights reserved.
//  店铺详情表头

#import "FDShopDetailHeaderView.h"
#import "Masonry.h"
#import "ImageLabelView.h"

@interface FDShopDetailHeaderView()
/**1.店铺图片*/
@property (nonatomic, strong) UIImageView *picIv;
/**店铺地址btn*/
@property (nonatomic, strong) UIButton *addressBtn;//按钮（图片 文字）
/**店铺电话btn*/
@property (nonatomic, strong) UIButton *phoneBtn; //
/**店铺介绍lb*/
@property (nonatomic, strong) UILabel *introduceLb;
/**1.店铺地址 view*/
@property (nonatomic,  strong) ImageLabelView *addressView;
/**2.电话view*/
@property (nonatomic,  strong) ImageLabelView *phoneView;

@end

@implementation FDShopDetailHeaderView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupView];
    }
    return self;
}

- (void)setupView {
    
    [self addSubview:self.picIv];
    [self addSubview:self.addressView];
    [self addSubview:self.phoneView];
    [self addSubview:self.introduceLb];
}

- (void)layoutSubviews {
    [super layoutSubviews];

    //2019-2-23 图片宽高比1：1
    [self.picIv mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self);
//        make.height.mas_equalTo(150);
        make.height.mas_equalTo(SCREEN_WIDTH);
    }];
    
    
    
    [self.addressView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left);//.offset(10);
        make.top.equalTo(self.picIv.mas_bottom);//.offset(10);
        make.right.equalTo(self.mas_right);
        make.height.mas_lessThanOrEqualTo(40);
    }];
    
    [self.phoneView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.addressView.mas_left);
        make.top.equalTo(self.addressView.mas_bottom).offset(2);
        make.right.equalTo(self.mas_right);
        make.height.mas_equalTo(20);
    }];
    
    [self.introduceLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.addressView.mas_left).offset(10);
        make.top.equalTo(self.phoneView.mas_bottom).offset(2);
        make.right.equalTo(self.mas_right).offset(-10);
        make.bottom.equalTo(self.mas_bottom);
    }];
}

#pragma mark - getter
- (UIImageView *)picIv {
    if (!_picIv) {
        _picIv = [UIImageView new];
    }
    return _picIv;
}

- (ImageLabelView *)addressView {
    if (!_addressView) {
        _addressView = [[ImageLabelView alloc] initWithFrame:CGRectMake(0, 0, 300, 20)];
        _addressView.iv.image = [UIImage imageNamed:@"address"];
    }
    return _addressView;
}

- (ImageLabelView *)phoneView {
    if (!_phoneView) {
        _phoneView = [[ImageLabelView alloc] initWithFrame:CGRectMake(0, 0, 300, 30)];
        _phoneView.iv.image = [UIImage imageNamed:@"dh"];
    }
    return _phoneView;
}


- (UILabel *)introduceLb {
    if (!_introduceLb) {
        _introduceLb = [UILabel new];
        _introduceLb.numberOfLines = 0;
        _introduceLb.font = [UIFont systemFontOfSize:15.0];
    }
    return _introduceLb;
}


#pragma mark - layout

#pragma mark - 重写setter 进行赋值
- (void)setHeaderModel:(ShopHeaderViewModel *)headerModel {
    _headerModel = headerModel;
    [self.picIv sd_setImageWithURL:[NSURL URLWithString:headerModel.thumbnail]];
    
    self.addressView.lb.text = headerModel.address;
    self.phoneView.lb.text = headerModel.phone;
    
    //介绍
    
    self.introduceLb.text = [NSString stringWithFormat:@"%@:\n%@",NSLocalizedString(L_DianPuJieShao, @"店铺介绍"),headerModel.outline];
}

@end
